package com.wlsk.license.common.execl.converter;


import cn.idev.excel.converters.Converter;
import cn.idev.excel.enums.CellDataTypeEnum;
import cn.idev.excel.metadata.GlobalConfiguration;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.metadata.property.ExcelContentProperty;
import cn.idev.excel.util.DateUtils;

import java.util.Date;
import java.util.Objects;

/**
 * <p>@Description : 时间格式转换</p>
 * <p>@Author : Zhangbin.Liu </p>
 * <p>@Date : 2019/9/3 16:27 </p>
 */
public class DateConverter implements Converter<Date> {


    @Override
    public Class<Date> supportJavaTypeKey() {
        return Date.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public WriteCellData<String> convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String format = "";
        if (!Objects.isNull(value)) {
            format = DateUtils.format(value, "yyyy-MM-dd HH:mm:ss");
        }
        return new WriteCellData<>(format);
    }
}
